package com.neighbor.neighborhoodadmin.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.neighbor.neighborhoodadmin.pojo.MallProductTypes;
import com.neighbor.neighborhoodadmin.service.IMallProductTypesService;
import com.neighbor.neighborhoodadmin.utils.ResponseMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 商品类型表 前端控制器
 * </p>
 *
 * @author song
 * @since 2025-09-22 09:11:23
 */

@RestController
@RequestMapping("/mallProductTypes")
public class MallProductTypesController {

    @Autowired
    private IMallProductTypesService productTypesService;

    @GetMapping("/list")
    public ResponseMsg list(@RequestParam(defaultValue = "1") Integer page,
                            @RequestParam(defaultValue = "10") Integer size) {
        Page<MallProductTypes> pageParam = new Page<>(page, size);
        Page<MallProductTypes> result = productTypesService.page(pageParam);
        return ResponseMsg.getInstance(ResponseMsg.SUCCESS, "查询成功", result);
    }

    @PostMapping("/add")
    public ResponseMsg add(@RequestBody MallProductTypes productType) {
        boolean success = productTypesService.save(productType);
        return success ? ResponseMsg.success("添加成功") :
                ResponseMsg.getInstance(ResponseMsg.DATA_ERROR, "添加失败");
    }

    @PutMapping("/update")
    public ResponseMsg update(@RequestBody MallProductTypes productType) {
        boolean success = productTypesService.updateById(productType);
        return success ? ResponseMsg.success("更新成功") :
                ResponseMsg.getInstance(ResponseMsg.DATA_ERROR, "更新失败");
    }

    @DeleteMapping("/delete/{id}")
    public ResponseMsg delete(@PathVariable Integer id) {
        boolean success = productTypesService.removeById(id);
        return success ? ResponseMsg.success("删除成功") :
                ResponseMsg.getInstance(ResponseMsg.DATA_ERROR, "删除失败");
    }
}